package dao;

import static org.junit.Assert.*;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;

import com.telkomsigma.hibernate.persistence.captain.dao.CaptainDao;
import com.telkomsigma.hibernate.persistence.captain.entity.Captain;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional
public class TestCaptainDao extends AbstractTransactionalJUnit4SpringContextTests {
	
	@Autowired
	@Qualifier("captainDaoImpl")
	private CaptainDao captainDao;
	
	@Test
	public void testCheckDaoConfig() {	
		assertNotNull(captainDao);
	}

	
	@Test
	public void testFindById(){
		Captain captain = captainDao.findById("1");
		assertNotNull(captain);
		
	}

	@Test
	public void testFindAllPlayer(){		
		List<Captain> playerList = captainDao.findAll(0,20);
		assertEquals(1, playerList.size());		
	}
	
	@Test
	public void testInsertCaptain() throws Exception{			
		Captain captain = new Captain();	
		captain.setTeam_id("2");
		captain.setPlayer_id("2");
		Captain result = captainDao.insert(captain);
		assertNotNull(result);
	}

	@Test
	public void testRemoveCaptain(){
		Captain captain = new Captain();
		captain.setPlayer_id("2");
		boolean check = captainDao.remove(captain);
		assertTrue(check==true);
	}	
}